package com.example.item01.controller;

import com.example.item01.anno.Log;
import com.example.item01.mapper.DeptMapper;
import com.example.item01.proj.Dept;
import com.example.item01.proj.Result;
import com.example.item01.service.DeptService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理Controller
 */
@Log4j2

@RestController

public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping("/depts")
    public Result list() {
        log.info("查询全部部门数据");
        List<Dept> listed = deptService.list();

        return Result.success(listed);
    }

    @Log
    @DeleteMapping("/depts/{id}")
    public Result delet(@PathVariable Integer id) {
        log.info("删除部门数据:" + id);
        deptService.delet(id);
        return Result.success();

    }
    @Log
    @PostMapping("/depts")
    public Result insert(@RequestBody Dept dept){
        log.info("添加部门数据");
        deptService.insert(dept);
        return Result.success();

    }

    @GetMapping("/depts/{id}")
public Result selectid(@PathVariable Integer id){
        log.info("编辑部门前奏");
        Dept dept=deptService.selectid(id);
        return Result.success(dept);

    }
    @Log
    @PutMapping("/depts")
public Result replace(@RequestBody Dept dept){
        log.info("修改部门后续");
        deptService.replace(dept);
        return Result.success();

    }


}
